# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_pyname=pyrsistent
_realname=pyrsistent
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.19.3
pkgrel=2
pkgdesc="Persistent/Functional/Immutable data structures (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/tobgu/pyrsistent'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python-flake8"
              "${MINGW_PACKAGE_PREFIX}-python-hypothesis")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.io/packages/source/p/pyrsistent/pyrsistent-${pkgver}.tar.gz")
sha512sums=('6bb70b6fd65b5cd9f961a3199c2d90725aaa66fb869e4eba2143735e2f3a7e4ecdc782b3498acc2d92e263c3bed14cec8cc77324f4ebd08c300ba6735db5ecf7')

prepare() {
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py pytest || warning "tests failed!!"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.mit "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENCE.mit"
}
